<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="sysErrorLogDelete" :butn-icon="'delete'" :butn-type="'primary'"
                                   :show-no-right="true" @click="delByIds(selectedRowKeys)">
                            {{$ti18('rxList.delBtn','删除')}}
                        </rx-button>
                        <rx-button :butn-icon="'retweet'"
                                   :butn-type="'danger'"
                                   :show-no-right="true" @click="deleteAll">{{i18n('list.clearBtn','清空')}}
                        </rx-button>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.msgId','消息ID')">
                            <a-input :placeholder="i18n('form.msgId','消息ID')" v-model="queryParam.Q_ID__S_EQ"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.trackId','跟踪ID')">
                            <a-input :placeholder="i18n('form.trackId','跟踪ID','input')"
                                     v-model="queryParam.Q_TRACE_ID__S_EQ"/>
                        </a-form-item>
                        <a-form-item :label="i18n('form.appName','应用名称')">
                            <a-select :options="apps" v-model="queryParam.Q_APP_NAME__S_EQ" allowClear></a-select>
                        </a-form-item>
                        <a-form-item :label="$ti18('rxForm.createTime','创建时间')">
                            <a-range-picker @change="onChange" allowClear>

                            </a-range-picker>
                        </a-form-item>
                        <a-form-item :label="i18n('form.url_','访问地址')">
                            <a-input :placeholder="i18n('form.url_','访问地址','input')" v-model="queryParam.Q_URL__S_LK"/>
                        </a-form-item>

                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :bordered="isBorder"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-system/system/core/sysErrorLog/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
            <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span @click="detail(record)">{{$ti18('rxList.detailBtn','明细')}}</span>
          </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
    import SysErrorLogApi from '@/api/system/core/sysErrorLog'
    import SysErrorLogDetail from './SysErrorLogDetail'
    import {BaseList, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";
    import PublicApi from "@/api/form/core/public.js";
    import SysLogApi from "@/api/system/core/sysLog";

    export default {
        name: 'SysErrorLogList',
        mixins: [BaseList],
        components: {
            RxFit
        },
        data() {
            return {
                columns: [
                    {
                        title: this.$ti18('rxList.index', '序号'),
                        type: 'indexColumn',
                        width: 40,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'}
                    },
                    {title: this.i18n('form.trackId', '跟踪ID'), dataIndex: 'traceId', width: 100},
                    {title: this.i18n('form.appName', '应用名称'), dataIndex: 'appName', width: 100},
                    {title: this.i18n('form.url_', '访问地址'), dataIndex: 'url', width: 150},
                    {title: this.$ti18('rxForm.createTime', '创建时间'), dataIndex: 'createTime', width: 100},
                    {
                        title: this.$ti18('rxList.action', '操作'),
                        width: 40,
                        dataIndex: 'action',
                        scopedSlots: {customRender: 'action'}
                    }
                ],
                detailcomponent: SysErrorLogDetail,
                comment: this.i18n('list.comment', '错误日志'),
                widthHeight: ['800px', '600px'],
                apps: []
            }
        },
        created() {
            this.getAllApps();
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "SysErrorLog", key);
            },
            delById(ids) {
                return SysErrorLogApi.del({ids: ids.join(',')});
            },
            getListByParams(parameter) {
                return SysErrorLogApi.query(parameter)
            },
            getAllApps() {
                PublicApi.getAppServices().then(res => {
                    this.apps = res.map(item => {
                        return {value: item, label: item};
                    });
                })
            },
            onChange(date, dateStr) {
                this.$set(this.queryParam, "Q_CREATE_TIME__D_GE", dateStr[0]);
                this.$set(this.queryParam, "Q_CREATE_TIME__D_LE", dateStr[1]);
            },
            deleteAll() {
                let self_ = this;
                this.$confirm({
                    title: self_.$ti18('rxMsa.actionTips', '操作提示'),
                    content:self_.i18n('msa.sureDelete','您确定要清空日志吗？'),
                    okText: self_.$ti18("rxForm.okBtn", "确定"),
                    cancelText: self_.$ti18("rxForm.cancelBtn", "取消"),
                    onOk() {
                        SysErrorLogApi.deleteAllSysErrorLog().then(res => {
                            this.$refs.table.loadData()
                        })
                    }
                })
            }

        }
    }
</script>
<style scoped>

</style>

